<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {

    /**
     * Match one field to another
     *
     * @access	public
     * @param	string
     * @param	field
     * @return	bool
     */
    public function is_unique($str, $field) {
        $tmparr = explode('.', $field);
        $table = $tmparr[0];
        $field = $tmparr[1];
        if (isset($tmparr[2]))
            $current_id = intval($tmparr[2]);

        $query = $this->CI->db->limit(1)->get_where($table, array($field => $str));

        if ($query->num_rows() <= 0)
            return TRUE;
        if (!isset($current_id))
            return FALSE;

        return $query->row()->id == $current_id;
    }

    public function set_error($field, $message) {
        $this->_field_data[$field]['error'] = $message;
        
        if (!isset($this->_error_array[$field])) {
            $this->_error_array[$field] = $message;
        }
    }
}
